import { S, U, getRequestId, mapField } from '../../lib/backend'
import Q from 'q'
import axios from 'axios'
import envFuncs from '@/config/base'
let env = envFuncs.getParams()

export default {
  getMsgCount ({rootState}, info) {
    let MSG_API_HOST = env.MSG_API_HOST
    return axios.get(MSG_API_HOST + '/users/' + rootState.app.token + '/message/count' + '?' + U(info || {}, false))
  },
  getMsgList ({rootState}, info) {
    let MSG_API_HOST = env.MSG_API_HOST
    return axios.get(MSG_API_HOST + '/users/' + rootState.app.token + '/message' + '?' + U(info || {}, false))
  },
  getCatMsgList ({rootState}, info) {
    let MSG_API_HOST = env.MSG_API_HOST
    return axios.get(MSG_API_HOST + '/users/' + rootState.app.token + '/message/' + info.cat_id + '?' + U(info || {}, false))
  },
  changeReadStatus ({rootState}, info) {
    let MSG_API_HOST = env.MSG_API_HOST
    const url = MSG_API_HOST + '/users/'
      + rootState.app.token + '/message/'
      + info.cat_id + '/read_status/'
      + info.read_status + '?'
      + U(info || {}, false)
    return axios.post(url, {}, {
      headers: {
        'Content-Type': 'application/json;charset=UTF-8'
      }})
  }
}
